<template>
	<view>
		<view class="content">
			<view class="title">订单编号：{{orderdata.orderNo}}</view>
			<view class="tgs">支付金额</view>
			<view class="money">￥{{orderdata.amount | priceFormat}}</view>
		</view>
		<view class="payee">
			<view class="heders">
				<view>收款方</view>
				<view>大橘邻里</view>
			</view>
			<view class="zhif">
				<view class="bt">支付方式</view>
				<view class="selce">
					<view class="iocn">
						<image src="/static/wx.png" mode="widthFix"></image>
						<view>微信支付</view>
					</view>
					<image class="go" src="/static/gx.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<view class="payment" @click="Payment">立即支付</view>
	</view>
</template>

<script>
	import { couponpay }  from '@/core/api/index.js'
	export default{
		data(){
			return{
				orderdata:{}
			}
		},
		onLoad(r) {
			console.log(JSON.parse(decodeURIComponent(r.data)))
			this.orderdata = JSON.parse(decodeURIComponent(r.data))
		},
		methods:{
			//确认支付
			// async Copayment(){
			// 	let parmes = {
			// 		id:this.id,
			// 	}
			// 	const { _data } = await orderpay(parmes)
			// 	let prdata  = _data
			// 	uni.requestPayment({
			// 	    provider: 'wxpay',
			// 		timeStamp: prdata.timeStamp,
			// 		nonceStr: prdata.nonceStr,
			// 		package: prdata.package,
			// 		signType: prdata.signType,
			// 		paySign: prdata.paySign,
			// 		success: async res=> {
			// 			console.log('success:' + JSON.stringify(res));
			// 			uni.showToast({
			// 				title:'支付成功',
			// 				icon:'none'
			// 			})
			// 			const data = await collect({ id: this.goodata.id, value: 0 })
			// 			this.$store.dispatch('user/getUserInfo')
			// 			setTimeout(()=>{
			//                uni.redirectTo({
			//                	url: '/pages/my/my_substi'
			//                });
			// 			},1000)
			// 		},
			// 		fail: function (err) {
			// 			console.log('fail:' + JSON.stringify(err));
			// 		}
			// 	});
			// },
			async Payment(){
				uni.showLoading({
					title:'拉起支付中...'
				})
				const { data } = await couponpay(this.orderdata.orderNo)
				console.log(data)
				uni.hideLoading()
				let prdata  = data
				uni.requestPayment({
				    provider: 'wxpay',
					timeStamp: prdata.timeStamp,
					nonceStr: prdata.nonceStr,
					package: prdata.packageValue,
					signType: prdata.signType,
					paySign: prdata.paySign,
					success: async res=> {
						console.log('success:' + JSON.stringify(res));
						uni.showToast({
							title:'支付成功',
							icon:'none'
						})
						// const data = await collect({ id: this.goodata.id, value: 0 })
						// this.$store.dispatch('user/getUserInfo')
						setTimeout(()=>{
				           uni.redirectTo({
				           	url: '/pages/coupon/successful?id=' + data.orderId
				           });
						},1000)
					},
					fail: function (err) {
						console.log('fail:' + JSON.stringify(err));
					}
				});
			}
		}
	}
</script>
<style>
	page{
		background: #F8F8F8;
	}
</style>
<style lang="scss">
	.content{
		margin: 40rpx 30rpx 20rpx;
		padding: 40rpx 0 20rpx;
		display: flex;
		justify-content: center;
	    flex-direction: column;
		align-items: center;
		background-color: #fff;
		border-radius: 20rpx;
		.title{
			color: #5F636B;
			font-size: 26rpx;
		}
		.tgs{
			margin: 28rpx 0;
		}
		.money{
			// font-weight: 600;
			font-size: 40rpx;
		}
	}
	.payee{
		padding: 40rpx 32rpx;
		margin: 00rpx 30rpx 20rpx;
		border-radius: 20rpx;
		background-color: #fff;
		.heders{
			display: flex;
			justify-content: space-between;
			border-bottom: 1rpx solid #F2F2F2;
			padding-bottom: 20rpx;
			view:nth-child(2){
				color: #818181;
			}
		}
		.zhif{
		    margin-top: 30rpx;
			font-size: 28rpx;
		}
		.selce{
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
			.iocn{
				display: flex;
				color: #515151;
				align-items: center;
				image{
					width: 25rpx;
					margin-right: 5rpx;
				}
			}
			.go{
				width: 40rpx;
				height: auto;
			}
		}
	}
	.payment{
		width: 500rpx;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		color: #fff;
		border-radius: 60rpx;
		margin: 160rpx auto;
		background-color: #F26B2E;
	}
</style>